<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('房间信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>请输入您要查询的公寓ID：</label>
                                <input type="text" name="roomId"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="room:roomInfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="room:roomInfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="room:roomInfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="room:roomInfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('room:roomInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('room:roomInfo:remove')}]];
        var reserveFlag = [[${@permission.hasPermi('room:roomInfo:reserve')}]];
        var prefix = ctx + "room/roomInfo";

        $.operate.reserve = function(id) {
            var url = prefix + "/reserve/" + id;
            $.modal.open("预约房间详情", url);
        };

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "房间信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '房间ID',
                    visible: false
                },
                {
                    field: 'roomPicture',
                    title: '房间图片',
                    formatter: function(value, row, index) {
                        return '<img src="' + value + '" alt="房间图片" style="width: 50px; height: 50px;">';
                    }
                },
                {
                    field: 'area',
                    title: '房间面积'
                },
                {
                    field: 'rentType',
                    title: '租金类型',
                    formatter: function(value, row, index) {
                        if (value === 'monthly') {
                            return '月租';
                        } else if (value === 'quarterly') {
                            return '季度';
                        } else if (value === 'yearly') {
                            return '年租';
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'roomType',
                    title: '房间类型'
                },
                {
                    field: 'hostPhone',
                    title: '房东联系方式'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + reserveFlag + '" href="javascript:void(0)" onclick="$.operate.reserve(\'' + row.id + '\')"><i class="fa fa-calendar"></i>预约</a>');                        
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        

        $.modal.open = function(title, url, width, height, callback) {
            //如果是移动端，就使用自适应大小弹窗
            if ($.common.isMobile()) {
                width = 'auto';
                height = 'auto';
            }
            if ($.common.isEmpty(title)) {
                title = false;
            }
            if ($.common.isEmpty(url)) {
                url = "/404.html";
            }
            if ($.common.isEmpty(width)) {
                width = 800;
            }
            if ($.common.isEmpty(height)) {
                height = ($(window).height() - 50);
            }
            if ($.common.isEmpty(callback)) {
                callback = function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    if (iframeWin.contentWindow.submitHandler) {
                        iframeWin.contentWindow.submitHandler(index, layero);
                    }
                }
            }
            layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                btn: ['确定','关闭'],
                // 弹层外区域关闭
                    shadeClose: true,
                yes: callback,
                cancel: function(index) {
                    return true;
                }
            });
        };
    </script>
</body>
</html>